package com.vic.Utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: Vic Ly
 */
public class dbutils {
    private static Properties props = new Properties();
    private static Map<String,Object> PROPER_MAP = new ConcurrentHashMap();
    static {
        InputStream is = null;
        try {
            is = dbutils.class.getClassLoader().getResourceAsStream("application-db.properties");
            props.load(is);
            Iterator<Object> iterator = props.keySet().iterator();
            while (iterator.hasNext()){
                String key = (String) iterator.next();
                PROPER_MAP.put(key,props.getProperty(key));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(is != null){
                try {
                    is.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

    public static String getString(String key){
        return (String) PROPER_MAP.get(key);
    }

//    public static void main(String[] args) {
//        System.out.println(getString("db.username"));
//    }
}
